package com.sgb.goods.widget.pop;

import android.content.Context;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.goods.R;
import com.sgb.goods.entity.AttributeViewEntity;
import com.sgb.goods.widget.MaxHeightRecyclerView;
import com.sgb.goods.widget.pop.adapter.GoodsAttributeViewAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;

import java.util.List;

/**
 * 描述：商品属性弹窗
 *
 * @author qiangHeNooo
 * <p>
 * 时间：2021.12.09
 */
public class GoodsAttributeViewWindows extends BasePopWindow<AttributeViewEntity> {

    private GoodsAttributeViewAdapter attributeViewAdapter;

    public GoodsAttributeViewWindows(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.goods_item_attribute_view;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        MaxHeightRecyclerView recyclerView = holder.getPop().findViewById(R.id.goods_recycler_view);
        TextView goodsConfirm = holder.getPop().findViewById(R.id.attr_goods_confirm);
        TextView goodsCancel = holder.getPop().findViewById(R.id.attr_goods_cancel);
        goodsConfirm.setOnClickListener(v -> {
            dissMiss();
            if (onResultClick != null) {
                onResultClick.result(attributeViewAdapter.getAttributeString(), null, null);
            }
        });
        goodsCancel.setOnClickListener(v -> dismiss());
        attributeViewAdapter = new GoodsAttributeViewAdapter(mContext, null);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(attributeViewAdapter);
    }

    public void setData(List<AttributeViewEntity> attributeViewEntityList, boolean isUpdate) {
        if (isUpdate) {
            attributeViewAdapter.clearAttributeString();
            attributeViewAdapter.setDatas(attributeViewEntityList);
        }
    }
}
